home *** CD-ROM | disk | FTP | other *** search
- Path: nntpd.lkg.dec.com!usenet
- From: wells@lkg.dec.com (Phil Wells)
- Newsgroups: comp.lang.c++
- Subject: How to initialize a private member struct
- Date: Sun, 10 Mar 1996 16:10:12 GMT
- Organization: Digital Equipment Corporation
- Message-ID: <4hse0q$q1o@nntpd.lkg.dec.com>
- NNTP-Posting-Host: pwrkdhcp31.lkg.dec.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hi,
-
- I have a program that joins single bitmaps into a larger bitmap
- "sheet" and also creates a .c file to describe the sheet layout. I
- broke up that base file into two pieces: the definition which I put in
- the class definition .h file and the data which I put in the .cpp
- file.
-
- When processing the bitmap data, I use this data to create a loop
- which first creates a DirectDrawSurface object for each of the image
- groups and then copies that surface's bitmap data to the surface
- object.
-
- Seems simple enough, but I immediatly got into problems because I had
- created a static definition for the sBitmap object (see example below)
- and it was referencing private data members out of scope.
-
- I experimented with various things including
- - making the sBitmap object a friend of my class
- - making the sBitmap object a static data member of my class
- - making the sBitmap object a public data member and referencing it
- with &sBitmap::s1
-
- Each of these had problems. Eventually I got tired of trying things
- and moved the LPDIRECTDRAW object pointers out of the class and into
- the .C file as static variables.
-
- I guess my basic question is how can I create class stuctures that
- contain pointers other members of the class at compile time?
-
- Thanks
-
- Phil
-
- // in the class .h file
- #define FRAMES_PER_ROW 8
- #define BITMAPFILE "ships.bmp"
-
- struct sBitmap
- {
- long RowSize;
- int ImageCount;
- int XFrameSize;
- int YFrameSize;
- struct sFrames
- {
- int StartFrame;
- int Count;
- LPDIRECTDRAWSURFACE *dds;
- } FrameData[6];
- };
-
-
- class x
- {
- .
- .
- .
- private
- LPDIRECTDRAWSURFACE s1;
- LPDIRECTDRAWSURFACE s2;
- LPDIRECTDRAWSURFACE s3;
- LPDIRECTDRAWSURFACE s4;
- LPDIRECTDRAWSURFACE s5;
- LPDIRECTDRAWSURFACE s6;
- };
- -----
-
- // in the class .cpp file
-
- static struct sShipBitmap =
- {
- 720000, 47, 300, 300,
- 0, 1, &s1 /* center */
- 1, 16, &s2 /* 360 loop */
- 17, 13, &s3 /* roll right */
- 30, 9, &s4 /* turn right 90 */
- 39, 8, &s5 /* turn left 90 */
- 0, 0};
-
-
-